// 维修单相关API
const baseUrl = 'http://localhost:8081'; // 后端接口地址

// 查询我的维修单列表
export const getMyWorkOrders = (params) => {
	return new Promise((resolve) => {
		// 模拟查询我的维修单
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					rows: [
						{
							workNo: 'WO001',
							rptNo: 'RPT001',
							assetNo: 'DKDKDEREWE',
							assetName: '一车间',
							faultDescription: '开关按钮按下去没有反应',
							statusCode: 'PENDING_EXEC',
							statusName: '待修理',
							startTime: null,
							endTime: null,
							createTime: '2021-03-23 14:53:32'
						},
						{
							workNo: 'WO002',
							rptNo: 'RPT002',
							assetNo: 'DKDKDEREWE',
							assetName: '二车间',
							faultDescription: '设备异常噪音',
							statusCode: 'IN_PROGRESS',
							statusName: '修理中',
							startTime: '2021-03-23 15:00:00',
							endTime: null,
							createTime: '2021-03-23 14:53:32'
						},
						{
							workNo: 'WO003',
							rptNo: 'RPT003',
							assetNo: 'DKDKDEREWE',
							assetName: '三车间',
							faultDescription: '温度异常',
							statusCode: 'PENDING_CONFIRM',
							statusName: '待确认',
							startTime: '2021-03-23 15:00:00',
							endTime: '2021-03-23 16:00:00',
							createTime: '2021-03-23 14:53:32'
						},
						{
							workNo: 'WO004',
							rptNo: 'RPT004',
							assetNo: 'DKDKDEREWE',
							assetName: '四车间',
							faultDescription: '压力不足',
							statusCode: 'PENDING_CONFIRM',
							statusName: '待确认',
							startTime: '2021-03-23 15:00:00',
							endTime: '2021-03-23 16:00:00',
							createTime: '2021-03-23 14:53:32'
						},
						{
							workNo: 'WO005',
							rptNo: 'RPT005',
							assetNo: 'DKDKDEREWE',
							assetName: '五车间',
							faultDescription: '润滑不良',
							statusCode: 'DONE',
							statusName: '已完成',
							startTime: '2021-03-23 15:00:00',
							endTime: '2021-03-23 16:00:00',
							createTime: '2021-03-23 14:53:32'
						}
					],
					total: 5
				}
			});
		}, 500);
	});
};

// 获取维修单详情
export const getWorkOrderDetail = (workNo) => {
	return new Promise((resolve) => {
		// 模拟获取维修单详情
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					workNo: workNo,
					rptNo: 'RPT001',
					assetNo: 'DKDKDEREWE',
					assetName: '一车间',
					faultDescription: '开关按钮按下去没有反应',
					statusCode: 'PENDING_EXEC',
					statusName: '待修理',
					faultCause: '按钮接触不良',
					countermeasure: '更换按钮开关',
					startTime: null,
					endTime: null,
					createTime: '2021-03-23 14:53:32'
				}
			});
		}, 500);
	});
};

// 更新维修单状态
export const updateWorkOrderStatus = (workNo, statusCode) => {
	return new Promise((resolve) => {
		// 模拟更新维修单状态
		setTimeout(() => {
			resolve({
				code: 200,
				message: '状态更新成功'
			});
		}, 1000);
	});
};

// 获取维修单状态履历
export const getWorkOrderHistory = (workNo) => {
	return new Promise((resolve) => {
		// 模拟获取维修单状态履历
		setTimeout(() => {
			resolve({
				code: 200,
				data: [
					{
						id: 1,
						stepName: '创建维修单',
						description: '维修单已创建',
						operatorId: 1,
						operatorName: '系统',
						startTime: '2021-03-23 14:53:32',
						endTime: '2021-03-23 14:53:32',
						result: 'SUCCESS'
					},
					{
						id: 2,
						stepName: '开始维修',
						description: '维修人员开始维修',
						operatorId: 2,
						operatorName: '杨文浩',
						startTime: '2021-03-23 15:00:00',
						endTime: null,
						result: 'IN_PROGRESS'
					}
				]
			});
		}, 500);
	});
};

// 接取维修任务
export const acceptWorkOrder = (workNo) => {
	return new Promise((resolve) => {
		// 模拟接取维修任务
		setTimeout(() => {
			resolve({
				code: 200,
				message: '接取成功'
			});
		}, 1000);
	});
};

// 开始维修
export const startWorkOrder = (workNo) => {
	return new Promise((resolve) => {
		// 模拟开始维修
		setTimeout(() => {
			resolve({
				code: 200,
				message: '开始维修'
			});
		}, 1000);
	});
};

// 完成维修
export const finishWorkOrder = (workNo) => {
	return new Promise((resolve) => {
		// 模拟完成维修
		setTimeout(() => {
			resolve({
				code: 200,
				message: '维修完成'
			});
		}, 1000);
	});
};

// 设置待料状态
export const setWaitingMaterial = (workNo) => {
	return new Promise((resolve) => {
		// 模拟设置待料状态
		setTimeout(() => {
			resolve({
				code: 200,
				message: '已设置为待料状态'
			});
		}, 1000);
	});
};

// 设置追加工状态
export const setExtraProcessing = (workNo) => {
	return new Promise((resolve) => {
		// 模拟设置追加工状态
		setTimeout(() => {
			resolve({
				code: 200,
				message: '已设置为追加工状态'
			});
		}, 1000);
	});
};
